package com.obtk.service.impl;

import com.obtk.mapper.CustomerMapper;
import com.obtk.mapper.SelChanceMapper;
import com.obtk.model.Customer;
import com.obtk.model.SelChance;
import com.obtk.service.CustomerService;
import com.obtk.util.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 功能说明
 *
 * @author Mr.Sun
 * @date 2023-03-29 15:34:42
 */
@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerMapper customerMapper;
    @Autowired
    private SelChanceMapper selChanceMapper;
    @Override
    public List<Customer> selectCustomer(Customer customer) {
        return customerMapper.selectCustomer(customer);
    }

    @Override
    public Customer selectByCustomerName(String custName) {
        return customerMapper.selectByCustomerName(custName);
    }
    //
    @Override
    public int register(Customer customer) {
        String uuId = UUIDUtil.getUniqueIdByUUId();
        System.out.println(uuId);
        customer.setCustId(uuId);
        customer.setCustLevel(1);
        customer.setCustLevelLabel("新客");
        customer.setCustSatisfy(5);
        customer.setCustCredit(10);
        customer.setCustStatus(1);
        customer.setCustOrderNum(0);
        customer.setCustBirthday(new Date());
        int a = customerMapper.insert(customer);
        return a;
    }

    @Override
    public Customer selectByCustomerId(Integer id) {
        return customerMapper.selectByCustomerId(id);
    }

    @Override
    public int updateByCustomerId(Customer customer) {
        customer.setCustBirthday(new Date());
        return customerMapper.updateByCustomerId(customer);
    }

    @Override
    public int updateStatusBatch(List<String> ids, Integer custStatus) {
        Map<String,Object> params = new HashMap<String,Object>(2);
        params.put("ids",ids);
        params.put("custStatus",custStatus);
        return customerMapper.updateStatusBatch(params);
    }

    @Override
    public int register2(Customer customer, SelChance selChance) {
        String uuId = UUIDUtil.getUniqueIdByUUId();
        customer.setCustId(uuId);
        customer.setCustLevel(1);
        customer.setCustLevelLabel("新客");
        customer.setCustSatisfy(5);
        customer.setCustCredit(10);
        customer.setCustStatus(1);
        customer.setCustOrderNum(0);
        List<SelChance> selChanceList = selChanceMapper.selectSelChance(selChance);
        customer.setCustBirthday(selChanceList.get(0).getChcBirthday());
        customer.setCustGender(selChanceList.get(0).getChcGender());
        System.out.println(selChanceList);
        int insert = customerMapper.insert(customer);
        return insert;
    }

    @Override
    public int updateOrder(Integer id) {
        return customerMapper.updateOrder(id);
    }


}
